<template>
	<view class="px-2">
		<block v-for="(item, index) in list" :key="index" v-if="userInfo !== ''">
			<view class="flex justify-between align-center py-3" hover-class="bg-light" @click="open(item.path)">
				<view class="flex align-center">
					<view class="pl-2">
						{{ item.title }}
					</view>
				</view>
				<view class="">
					<text class="iconfont icon-youjiantou text-muted"></text>
				</view>
			</view>
		</block>
		<view class="flex justify-between align-center py-3" hover-class="bg-light" @click="clearstory">
			<view class="flex align-center">
				<view class="pl-2">清理缓存</view>
			</view>
			<view class="">
				<text>{{ size }}</text>
			</view>
		</view>

		<view class="" style="margin-top: 50rpx">
			<button style="border-radius: 50rpx" class="text-light bg-main mt-3" @click="loginornout">{{ userInfo !== '' ? '退出登录' : '前去登录' }}</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [
				{
					title: '账号与安全',
					path: '/pages/revisepass/revisepass'
				},
				{
					title: '资料编辑',
					path: '/pages/user-info/user-info'
				},
				{
					title: '绑定邮箱',
					path: '/pages/emial/emial'
				},
				{
					title: '第三方登录绑定',
					path: '/pages/other/other'
				},
				{
					title: '意见反馈',
					path: '/pages/user-feedback/user-feedback'
				},
				{ title: '关于社区', path: '/pages/about/about' }
			],
			size: 0,
			userInfo: ''
		};
	},
	onLoad() {
		this.getstory();
		this.userInfo = uni.getStorageSync('userInfo');
	},
	methods: {
		open(path) {
			if (path) {
				uni.navigateTo({
					url: path
				});
			}
		},
		loginornout() {
			if (this.userInfo !== '') {
				uni.showModal({
					title: '确定退出吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: (res) => {
						if (res.confirm) {
							uni.removeStorageSync('userInfo');
							uni.removeStorageSync('token');
							uni.switchTab({
								url: '/pages/my/my',
								success:()=> {
									// 关闭Socket
									this.$store.commit('CloseSocket');
									uni.showToast({
										title: '已退出',
										icon: 'none'
									});
								}
							});
						}
					}
				});
			} else {
				uni.navigateTo({
					url: '/pages/login/login'
				});
			}
		},
		getstory() {
			uni.getStorageInfo({
				success: (res) => {
					this.size = res.currentSize > 1024 ? (res.currentSize / 1024).toFixed(2) + 'MB' : res.currentSize.toFixed(2) + 'KB';
				}
			});
		},
		clearstory() {
			uni.clearStorage({
				success: () => {
					this.$store.dispatch('updateTabarBadge')
					this.$store.state.SocketTask.close();
					this.$store.state.SocketTask = false;
					this.getstory();
					
				}
			});
			uni.showToast({
				title: '清理成功',
				icon: 'none'
			});
		}
	}
};
</script>

<style></style>
